<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('resize_image'))
{
	function resize_image($image,$path,$url,$width,$height,$title = '',$prefix = '')
	{
		$CI =& get_instance();
		
		if (!strlen($image)){
			$image = 'no_image_available.jpg';
		}
			
		if (!file_exists($path . $prefix .'_' . $image)){
			$CI->load->library('image_moo');
			$CI->image_moo
		        ->load($path . $image)
		        ->resize_crop($CI->config->item($width),$CI->config->item($height))
		        ->save($path . $prefix . '_' . $image);
		}
		
		return '<img src="' . $url . $prefix . '_' . $image . '" width="' . $CI->config->item($width) . '" height="' . $CI->config->item($height) . '" title="' . $title . '" alt="' . $title . '"/>';
	}
}

if ( ! function_exists('resize_parent_image'))
{
	function resize_parent_image($parentId,$path,$url,$width,$height,$title = '',$prefix='')
	{
		$CI =& get_instance();
			
		$CI->load->model('product_model');
		
		$product = $CI->product_model->getProductList(array('id' => $parentId))->result();
		
		if (!strlen($product[0]->url)){
			$image = 'no_image_available.jpg';
		} else {
			$image = $product[0]->url;
		}
		
		if (!file_exists($path . $prefix . '_' . $image)){
			$CI->load->library('image_moo');
			$CI->image_moo
		        ->load($path . $image)
		        ->resize_crop($CI->config->item($width),$CI->config->item($height))
		        ->save($path . $prefix . '_' . $image);
		}
		
		return '<img src="' . $url . $prefix . '_' . $image . '" width="' . $CI->config->item($width) . '" height="' . $CI->config->item($height) . '" title="' . $title . '" alt="' . $title . '"/>';
	}	
}